package Test_0814.book;

import java.util.Objects;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-08-14
 */
/*书：
    书名；
    作者姓名；
    价格；
    书的类型；
    是否借出；*/
//使用private进行封装
public class Book {
    private String bookName;
    private String author;
    private int price;
    private String type;
    //这里注意一下Boolean是包装类， 如果你写成private Boolean isBorrow，那么你的默认赋值会是null
    //而使用boolean是基本类型，你的默认赋值是false
    private boolean isBorrow;
    //不用对isBorrow进行初始化，默认为false表示未借出
    public Book(String bookName, String author, int price, String type) {
        this.bookName = bookName;
        this.author = author;
        this.price = price;
        this.type = type;
    }

    public String getBookName() {
        return bookName;
    }
    public void setBookName(String bookName) {
        this.bookName = bookName;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public Boolean getBorrow() {
        return isBorrow;
    }
    public void setBorrow(Boolean borrow) {
        isBorrow = borrow;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Book book = (Book) o;
        return bookName.equals(book.bookName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(bookName);
    }

    @Override
    public String toString() {
        return "Book{" +
                "bookName='" + bookName + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                //如果等于true表示已借出，否则未借出
                 ( (isBorrow == true) ? "已借出" : "未借出" )+
                '}';
    }

}

